package com.getpebble.android.widget;

import android.content.Context;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.style.StyleSpan;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import com.getpebble.android.R;

public class CustomToast {
    public static void show(Context context, String title, String subTitle, String description, int descTextColor) {
        if (!TextUtils.isEmpty(title)) {
            View toastView = View.inflate(context, R.layout.custom_toast, null);
            TextView txtTitle = (TextView) toastView.findViewById(R.id.txt_title);
            TextView txtDesc = (TextView) toastView.findViewById(R.id.txt_description);
            Spannable boldText = new SpannableString(title);
            boldText.setSpan(new StyleSpan(1), 0, title.length(), 33);
            if (TextUtils.isEmpty(subTitle)) {
                txtTitle.setText(boldText);
            } else {
                txtTitle.setText(new SpannableStringBuilder(boldText).append(" ").append(subTitle));
            }
            if (TextUtils.isEmpty(description)) {
                txtDesc.setVisibility(8);
            } else {
                txtDesc.setTextColor(descTextColor);
                txtDesc.setText(description);
            }
            Toast toast = new Toast(context);
            toast.setDuration(1);
            toast.setView(toastView);
            toast.show();
        }
    }

    public static void show(Context context, String message, int textColor) {
        if (!TextUtils.isEmpty(message)) {
            View toastView = View.inflate(context, R.layout.custom_toast, null);
            TextView txtTitle = (TextView) toastView.findViewById(R.id.txt_title);
            ((TextView) toastView.findViewById(R.id.txt_description)).setVisibility(8);
            txtTitle.setTextColor(textColor);
            txtTitle.setText(message);
            Toast toast = new Toast(context);
            toast.setDuration(1);
            toast.setView(toastView);
            toast.show();
        }
    }
}
